home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / SCC Hack ƒ / SccHack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-23  |  2.2 KB  |  95 lines  |  [TEXT/KAHL]

  1. /*
  2.     This code was created by Keith Evans, MMATS, Inc. with alot of
  3.     help from others whom I met on the GEnie network service.
  4.     
  5.     This code fragment will initialize the SCC chip to receive serial
  6.     data from the modem port. The data consists of 8 data bits, 1 stop
  7.     bit, no parity, and the clocking will come from the "HSKi" pin. The
  8.     data is received at the same rate as the clock (1X mode).
  9.     
  10.     I wish to thank the makers of THINK's LightSpeed C for a very good
  11.     development environment, at least VERY good for this programmer!
  12.  
  13.  
  14. */
  15.  
  16. #define    NULL    0L
  17. #define aCtl    2      /* controls for the modem port */
  18. #define aData    6      /* data from the modem port */
  19.  
  20. #define PAUSE    asm    {move.l (SP),(SP)}    /* to avoid overdriving the SCC */
  21.  
  22. #define ZERO(thereg)    asm    {move.b #0,(thereg)} /* because LSC doesn't  */
  23.                                                  /* know from volatile & */
  24.                                                  /* will generate clrs   */
  25.  
  26.  
  27. /* main program */
  28.  
  29. main()
  30. {
  31.     int     vRef;
  32.     Str255    fn;
  33.  
  34.     InitMac();
  35.     SCCSetup();                /* Initialize SCC */
  36.     
  37.     }
  38.  
  39. SCCSetup() {            /* configure SCC */
  40.     char    toss;
  41.     register char *SCCWR0 = (SCCWr + aCtl);
  42.     register char *SCCRD0 = (SCCRd + aCtl);
  43.     
  44.    toss        =    *SCCRD0;    /* read SCC to reset it */
  45.    PAUSE
  46.    *SCCWR0    =    0x9;
  47.    PAUSE
  48.    *SCCWR0    =    0x88;    /* reset the SCC channel A & enable all interrupts */
  49.    PAUSE
  50.    *SCCWR0    =    0x1;
  51.    PAUSE
  52.    *SCCWR0    =    0x1;    /* disable Rx interrupts & enable external status interrupts  */
  53.    PAUSE
  54.    *SCCWR0    =    0x4;
  55.    PAUSE
  56.    *SCCWR0    =    0x4;    /* X1 clock mode & 1 stop bit */
  57.    PAUSE
  58.    *SCCWR0    =    0x2;
  59.    PAUSE
  60.    ZERO(SCCWR0)            /* reset all interrupt vectors */
  61.    PAUSE
  62.    *SCCWR0    =    0x3;
  63.    PAUSE
  64.    *SCCWR0    =    0xC0;    /* Rx 8 bits/character */
  65.    PAUSE
  66.    *SCCWR0    =    0x5;
  67.    PAUSE
  68.    *SCCWR0    =    0x60;    /* Tx 8 bits/character */
  69.    PAUSE
  70.    *SCCWR0    =    0xA;
  71.    PAUSE
  72.    ZERO(SCCWR0)            /* NRZ encoding */
  73.    PAUSE
  74.    *SCCWR0    =    0xB;
  75.    PAUSE
  76.    *SCCWR0    =    0x30;    /* TTL input, use TRxC for Rx & BR generator for Tx, TRxC input */
  77.    PAUSE
  78.    *SCCWR0    =    0xE;
  79.    PAUSE
  80.    *SCCWR0    =    0x1;    /* enable baud generator */
  81.    PAUSE
  82.    *SCCWR0    =    0x3;
  83.    PAUSE
  84.    *SCCWR0    =    0xC1;    /* enable receiver */
  85.    PAUSE
  86.    *SCCWR0    =    0x5;
  87.    PAUSE
  88.    *SCCWR0    =    0x60;    /* RTS high */
  89.    PAUSE
  90.    *SCCWR0    =    0xF;
  91.    PAUSE
  92.    *SCCWR0    =    0x8;    /* enable mouse interrupts */
  93. }
  94.  
  95.